Skip to content

refactor(onekeylib): split the Protocol V2 client by responsibility - #1010

Merged
wabicai merged 2 commits into
feat/onekeylib-pythonfrom
refactor/onekeylib-protocol-v2-split
Dec 3, 2026
Merged

wabicai merged 2 commits into
feat/onekeylib-pythonfrom
refactor/onekeylib-protocol-v2-split

Conversation

@wabicai

@wabicai wabicai commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Step 1 of the onekeylib architecture cleanup: split the 870-line protocol_v2.py by responsibility. No behavior change. OneKeyClientV2 keeps every public method and sends the same requests in the same order.

Stacked on #1003. The base is feat/onekeylib-python. Once #1003 merges, retarget this PR to onekey.

Module What it holds
protocol_v2/client.py OneKeyClientV2: request dispatch, device state, the session registry (655 lines, down from 870)
protocol_v2/link.py message encoding over proto_link, LinkState (handshake, eventless, generation), the ProtocolInfo check
protocol_v2/requests.py request classes: mid-workflow, management, session, seedless, interactive
protocol_v2/failures.py failure_error(): V2Failure / Failure replies to exceptions
protocol_v2/sessions.py SessionV2, passphrase_request() (which passphrase request each PassphraseSetting sends), checks on DeviceSession replies
protocol_v2/workflow.py WorkflowReservation: the signing exchange a session keeps reserved (formerly three client attributes)

from onekeylib.protocol_v2 import OneKeyClientV2, SessionV2, REQUIRED_V2_MESSAGES still works. The Electrum plugin imports nothing from protocol_v2 directly.

The first commit only moves the file, so git log --follow still traces the client's history.

Tests

  • onekeylib: pytest tests passed 69. flake8 --select=E9,F63,F7,F82,F401,F811 passed. The only test change: two private attributes are now reached through client._workflow.session / .token. No assertion changed.
  • The Electrum plugin tests (tests/plugins/onekey, run against this source) passed 164.
  • The built wheel contains onekeylib/protocol_v2/*.py and no stale protocol_v2.py.
  • Not tested on a real device.

Next steps (separate PRs)

  1. btc.py stops probing V2 internals with getattr and uses a base-class signing guard instead. get_client / get_default_session stop dispatching on isinstance.
  2. Unify the transport message interface. Remove leftover trezorlib code (Cardano, THP, the dead tools.__getattr__). Name the timeout and seed-domain constants.

🤖 Generated with Claude Code

wabicai and others added 2 commits December 3, 2026 11:15
Move only: the module becomes protocol_v2/client.py with parent-relative
imports, and protocol_v2/__init__.py re-exports OneKeyClientV2, SessionV2
and REQUIRED_V2_MESSAGES, so `from onekeylib.protocol_v2 import ...` keeps
working. Keeping the move apart from the split lets `git log --follow`
trace the client's history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No behavior change. OneKeyClientV2 keeps every public method and the order
of every request it sends; its parts move into modules of their own:

- link: message encoding over proto_link, the negotiated link state
  (LinkState) and the ProtocolInfo check.
- requests: which requests are mid-workflow, seedless, interactive, and so on.
- failures: failure replies to exceptions (failure_error).
- sessions: SessionV2, the passphrase request each PassphraseSetting sends,
  and the checks on DeviceSession replies.
- workflow: the signing exchange a session keeps reserved
  (WorkflowReservation), formerly three client attributes.

The tests reach the reservation as client._workflow.session/.token instead
of the old attributes; their assertions are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sidmorizon

Copy link
Copy Markdown
Contributor

@codex review

@sidmorizon

Copy link
Copy Markdown
Contributor

@codex security review

@sidmorizon

Copy link
Copy Markdown
Contributor

Cursor review failed.

Remote error: cursor_permission_denied: HTTP 403 Forbidden: Cloud Agent is not available for free users. Please upgrade to Pro.

@cursor

cursor Bot commented Dec 3, 2026

Copy link
Copy Markdown

Skipping Bugbot: Bugbot is disabled for this repository. Visit the Bugbot dashboard to update your settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T03:31:12.803140Z 71744a4 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Unknown error
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sidmorizon

Copy link
Copy Markdown
Contributor

Devin Cloud review ↗

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 71744a47cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sidmorizon

Copy link
Copy Markdown
Contributor

@wabicai
wabicai merged commit 71744a4 into feat/onekeylib-python Dec 3, 2026
9 checks passed
@wabicai
wabicai deleted the refactor/onekeylib-protocol-v2-split branch December 3, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants